package com.wooophone.buyi.web.action;

import weibo4j.Account;
import weibo4j.Oauth;
import weibo4j.Weibo;
import weibo4j.http.AccessToken;
import weibo4j.model.WeiboException;
import weibo4j.org.json.JSONObject;

import com.wooophone.common.web.action.BaseAction;

public class IndexAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String code;

	public void setCode(String code) {
		this.code = code;
	}

	@Override
	public String execute() throws Exception {

//		setCookie("user", "minglic",1000000);
//		setCookie("password", "minglic",3600*24*7);
		
		System.out.println("user:"+getCookie("user"));
		System.out.println("password:"+getCookie("password"));

		System.out.println("进来了");

		return super.execute();
	}

	public String weiboLogin() {
		try {
			Oauth oauth = new Oauth();
			if(code==null){
				String url = oauth.authorize("code");
				setRedirectUrl(url);
				return REDIRECT;
			}else{
				AccessToken accessToken = oauth.getAccessTokenByCode(code);
				System.out.println(accessToken.getAccessToken());
				System.out.println(accessToken.getRateLimitLimit());
				System.out.println(accessToken.getRateLimitRemaining());
				System.out.println(accessToken.getRateLimitReset());
				return "login_ok";
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}

	public static void main(String[] args) throws WeiboException {
		Oauth oauth = new Oauth();
		AccessToken accessToken = oauth.getAccessTokenByCode("c166313057d0620cc440cb7666a400d6");
		System.out.println(accessToken.getAccessToken());
		System.out.println(accessToken.getExpireIn());
		System.out.println(accessToken.getAccessToken());
		System.out.println(accessToken.toString());
		
		Weibo weibo = new Weibo();
		String access_token = args[0];
		weibo.setToken(access_token);
		Account am = new Account();
		try {
			JSONObject uid = am.getUid();
		} catch (WeiboException e) {
			e.printStackTrace();
		}
	}
}
